package net.bwie.vehicle.dws.function1;

import net.bwie.realtime.guanjuntao.util.DateTimeUtil;
import net.bwie.vehicle.dws.bean1.VehicleData;
import org.apache.flink.streaming.api.functions.ProcessFunction;
import org.apache.flink.util.Collector;

public class AbnormalReportAnEmergencyFunction extends ProcessFunction<VehicleData,String>{
    public void processElement(VehicleData value, ProcessFunction<VehicleData, String>.Context ctx, Collector<String> out) throws Exception {
        String timeStamp = DateTimeUtil.convertLongToString(value.getTimestamp(), DateTimeUtil.DATE_TIME_FORMAT);
        // 定义其他提示信息
        final Double MinBatteryLevel = 10.0;
        final Double MaxSpeed = 100.0;

        if (value.getBatteryLevel() != null && value.getBatteryLevel() < MinBatteryLevel) {
            // 输出报警信息
            String join = String.join(",", timeStamp, timeStamp, value.getVin(), "电池电量低于10%");
            out.collect(join);
        }
        if (value.getSpeed() != null && value.getSpeed() > MaxSpeed) {
            // 输出报警信息
            String join2 = String.join(",", timeStamp, timeStamp, value.getVin(), "车辆速度过高");
            out.collect(join2);
        }
    }
}
